local httparg    = require("shared.api.httparg")
local response   = require("shared.api.response")
local tag        = httparg.tag()
local assertion  = httparg.assertion


local ARGS = {
  tag.body('json', 'required'),

  locale   = tag.json.locale  ('string', 'required', assertion.non_empty_string() ),
}

local RESULT
do
  local dataapi   = require("shared.api.dataapi")

  local reply, err = dataapi.level.view(
    {
      locale   = ARGS.locale,
    })

  if err then
    response.error(err)
  end

  RESULT = reply
end

-- response
local mapper = require("shared.object.mapper")
response.success(
  mapper.map(RESULT, {
    content = mapper.ListMapper(
      "content", {
        level         = "title",
        code          = "level",
        bonus         = "bonus",
        qualification = "qualification",
      }
    )
  })
)
